package com.wst.system.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wst.system.interceptor.encrypt.EncryptDecrypt;
import com.wst.system.security.IsAdmin;
import com.wst.system.security.IsSecurity;
import com.wst.system.util.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wst.system.config.exception.GlobalExcetion;
import java.io.Serializable;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.wst.system.server.service.SysConfigService;
import com.wst.system.server.entity.SysConfig;
import com.wst.system.server.entity.vo.SysConfigVo;
import com.wst.system.server.entity.vo.PageSearchVo;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import java.util.Map;

import com.wst.system.server.entity.vo.DelManyDataVo;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author X.I.O
 * @since 2025-03-04
 */

@Slf4j
@RestController
@Api(tags = {"的服务类"})
@RequestMapping("/sys-config")
public class SysConfigController  {

        @Autowired
        private SysConfigService sysConfigService;

        @EncryptDecrypt
        @IsAdmin
        @PostMapping("/getsysconfig")
        public JSONObject getSysConfig(){
            List<SysConfig> sysConfigs=sysConfigService.list();
            return ResultUtil.successInfo(sysConfigs);
        }

        @PostMapping("/encrypt/saveorupdate")
        @EncryptDecrypt
        public JSONObject saveOrUpdate(Map<String,Object> map) throws GlobalExcetion {
           log.info(JSONObject.toJSONString(map));
             sysConfigService.saveOrUpdateSysConfig(map);
            return ResultUtil.successInfo("更新成功");
        }


        @IsSecurity(isSecurity = false)
        @ApiOperation("获取网站名称")
        @EncryptDecrypt
        @PostMapping("getwebname")
        public JSONObject getWebName(){
            SysConfig sysConfig=sysConfigService.getWebName();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("webname",sysConfig.getSysValue());
            return ResultUtil.successInfo(jsonObject);
        }


}

